-- ----------------------------------------------------------------------------
-- MySQL Workbench Migration
-- Migrated Schemata: dbo
-- Source Schemata: dbo
-- Created: Sat Dec 22 13:22:44 2012
-- ----------------------------------------------------------------------------

SET FOREIGN_KEY_CHECKS = 0;;

-- ----------------------------------------------------------------------------
-- Schema dbo
-- ----------------------------------------------------------------------------
DROP SCHEMA IF EXISTS `QuickChatApplication` ;
CREATE SCHEMA IF NOT EXISTS `QuickChatApplication` COLLATE utf8_general_ci ;

-- ----------------------------------------------------------------------------
-- Table dbo.Talkers
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `QuickChatApplication`.`Talkers` (
  `TalkerId` INT NOT NULL AUTO_INCREMENT ,
  `FirstName` VARCHAR(30) NULL ,
  `LastName` VARCHAR(30) NULL ,
  `ChatAlias` VARCHAR(30) NOT NULL ,
  `EmailAddress` VARCHAR(50) NULL ,
  `CurrentRoomId` INT NULL ,
  PRIMARY KEY (`TalkerId`) ,
  CONSTRAINT `FK_Talkers_ChatRooms`
    FOREIGN KEY (`CurrentRoomId` )
    REFERENCES `QuickChatApplication`.`ChatRooms` (`RoomId` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- Table dbo.ChatRooms
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `QuickChatApplication`.`ChatRooms` (
  `RoomId` INT NOT NULL AUTO_INCREMENT ,
  `CreatorsId` INT NOT NULL ,
  `CreatedTime` DATETIME NOT NULL ,
  PRIMARY KEY (`RoomId`) )
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- Table dbo.ChatSessions
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `QuickChatApplication`.`ChatSessions` (
  `SessionId` INT NOT NULL AUTO_INCREMENT ,
  `StartTime` DATETIME NOT NULL ,
  PRIMARY KEY (`SessionId`) )
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- Table dbo.Messages
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `QuickChatApplication`.`Messages` (
  `MessageId` INT NOT NULL AUTO_INCREMENT ,
  `MessageText` VARCHAR(1000) NOT NULL ,
  `SendersId` INT NOT NULL ,
  `SessionId` INT NOT NULL ,
  `SentTime` DATETIME NOT NULL ,
  PRIMARY KEY (`MessageId`) ,
  CONSTRAINT `FK_Messages_Talkers`
    FOREIGN KEY (`SendersId` )
    REFERENCES `QuickChatApplication`.`Talkers` (`TalkerId` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `FK_Messages_ChatSessions`
    FOREIGN KEY (`SessionId` )
    REFERENCES `QuickChatApplication`.`ChatSessions` (`SessionId` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- Table dbo.sysdiagrams
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `QuickChatApplication`.`sysdiagrams` (
  `name` VARCHAR(160) NOT NULL ,
  `principal_id` INT NOT NULL ,
  `diagram_id` INT NOT NULL AUTO_INCREMENT ,
  `version` INT NULL ,
  `definition` LONGBLOB NULL ,
  PRIMARY KEY (`diagram_id`) ,
  UNIQUE INDEX `UK_principal_name` (`principal_id` ASC, `name` ASC) )
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- Table dbo.SessionTalkers
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `QuickChatApplication`.`SessionTalkers` (
  `SessionId` INT NOT NULL ,
  `TalkerId` INT NOT NULL ,
  PRIMARY KEY (`SessionId`, `TalkerId`) ,
  CONSTRAINT `FK_SessionTalkers_Talkers`
    FOREIGN KEY (`TalkerId` )
    REFERENCES `QuickChatApplication`.`Talkers` (`TalkerId` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `FK_SessionTalkers_ChatSessions`
    FOREIGN KEY (`SessionId` )
    REFERENCES `QuickChatApplication`.`ChatSessions` (`SessionId` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
COLLATE = utf8_general_ci;
SET FOREIGN_KEY_CHECKS = 1;;
